﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Geometry;
using System.Diagnostics;

namespace TestGeometry {
    public class TestTransform {
        public void run() {
            testTranslate();
            testScale();
            testRotateX();
            testLookAt();
        }

        public void testTranslate() {
            float amp = 10.0f;
            Vector vamp = new Vector(amp, amp, amp);
            Transform tr = Transform.translate(vamp);

            Vector ve = new Vector(0.0f, 0.0f, 0.0f);
            Vector v = tr * ve;
            Util.assertEquals(v.x, ve.x);
            Util.assertEquals(v.y, ve.y);
            Util.assertEquals(v.z, ve.z);

            Vector w = tr.getInverse() * v;
            Util.assertZero((w - v).length());

            Point pe = new Point(0.0f, 0.0f, 0.0f);
            Point p = tr * pe;
            Util.assertEquals(p.x, amp);
            Util.assertEquals(p.y, amp);
            Util.assertEquals(p.z, amp);

            Point q = tr.getInverse() * p;
            Util.assertZero(q.distance(pe));
        }

        public void testScale() {
            float amp = 10.0f;
            Vector vamp = new Vector(amp, amp, amp);
            Transform tr = Transform.scale(amp, amp, amp);

            Vector ve = new Vector(1.0f, 1.0f, 1.0f);
            Vector v = tr * ve;
            Util.assertEquals(v.x, amp);
            Util.assertEquals(v.y, amp);
            Util.assertEquals(v.z, amp);

            Point pe = new Point(1.0f, 1.0f, 1.0f);
            Point p = tr * pe;
            Util.assertEquals(p.x, amp);
            Util.assertEquals(p.y, amp);
            Util.assertEquals(p.z, amp);

            Vector w = tr.getInverse() * v;
            Util.assertEquals(w.x, ve.x);
            Util.assertEquals(w.y, ve.y);
            Util.assertEquals(w.z, ve.z);

            Point q = tr.getInverse() * p;
            Util.assertEquals(q.x, pe.x);
            Util.assertEquals(q.y, pe.y);
            Util.assertEquals(q.z, pe.z);
        }

        public void testRotateX() {
            // TODO
        }

        public void testLookAt() {
            float bias = 10.0f;
            Point cppos = new Point(bias, bias, bias);
            Vector cvdiff = new Vector(bias, bias, bias);
            Point cplook = cppos + cvdiff;

            Transform tr = Transform.LookAt(cppos, cplook, Vector.UP);
            Point tp = tr * cplook;
            Util.assertEquals(tp.x, 0);
            Util.assertEquals(tp.y, 0);
            Util.assertEquals(tp.z, cvdiff.length());
        }
    }
}
